﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ICTBilling;

/// <summary>
/// Summary description for tbEquipment
/// </summary>
public partial class tbEquipment : IValidate
{
    public List<ExceptionHandler> Validate(ChangeAction changeAction)
    {
        List<ExceptionHandler> ExecutionCollection = new List<ExceptionHandler>();
        try
        {
            if (changeAction == ChangeAction.Insert ||
                changeAction == ChangeAction.Update)
            {
                if (changeAction == ChangeAction.Update && this.PkEquipmentID == null)
                    ExecutionCollection.Add(new ExceptionHandler("PkEquipmentID", "شناسه تجهیزات", ICTBilling.ExceptionType.NullArgumant));

                if (this.EquipmentName == null)
                    ExecutionCollection.Add(new ExceptionHandler("EquipmentName", "نام تجهیزات", ICTBilling.ExceptionType.NullArgumant));

                if (this.Description == null)
                    ExecutionCollection.Add(new ExceptionHandler("Description", "توضیحات", ICTBilling.ExceptionType.NullArgumant));

                if (this.ElectricUsage == null)
                    ExecutionCollection.Add(new ExceptionHandler("ElectricUsage", "میزان برق مصرفی", ICTBilling.ExceptionType.NullArgumant));
                else
                {
                    try
                    {
                        int.Parse(this.ElectricUsage.ToString());
                    }
                    catch (FormatException)
                    {
                        ExecutionCollection.Add(new ExceptionHandler("ElectricUsage", "میزان برق مصرفی", ICTBilling.ExceptionType.IntFormat));
                    }
                }

                if (this.EquipmentCode == null)
                    ExecutionCollection.Add(new ExceptionHandler("EquipmentCode", "کد شناسایی تجهیزات", ICTBilling.ExceptionType.NullArgumant));
                
            }
        }
        catch (Exception _Exception)
        {
            ExecutionCollection.Add(new ExceptionHandler(_Exception));
        }
        return ExecutionCollection;
    }
}